#ifndef THREAD
#define THREAD
#include <func.h>
#include "taskQueue.h"

typedef struct threadPool_s{
    int workNum;
    pthread_t* workArr;
    taskQueue_t task;
    pthread_mutex_t mutex;
    pthread_cond_t cond;
}threadPool_t;

typedef struct dirNode_s{
    char dirName[256];
    struct dirNode_s *pNext;
}dirNode_t;

typedef struct dirQueue_s{
    dirNode_t *pFornt;
    dirNode_t *pRear;
    int size;
}dirQueue_t;

typedef struct dirID_s{
    dirQueue_t userID;
    char pwdID[256];
}dirID_t;

enum{
    OD_CD,
    OD_LS,
    OD_PTS,
    OD_GTC,
    OD_RM,
    OD_PWD,
    OD_MD,
    OD_RD
};

typedef struct train_s{
    int status;
    int length;
    char buf[1000];
}train_t;

typedef struct userinfo_s{
    char username[20];
    char password[50];
}userinfo_t;

int initThreadPool(threadPool_t *thread,int num);
int makeTaskQueue(taskQueue_t * queue);
int enQueue(taskQueue_t * queue,int netfd);
int outQueue(taskQueue_t * queue);
int setTCP(char *IP,char*port,int*psockfd);
int epollAdd(int epfd,int fd);
int epollDel(int epfd,int fd);
int makeWork(threadPool_t * thread);
void* threadFunc(void* arg);
int outDirQueue(dirQueue_t * queue);
int enDirQueue(dirQueue_t * queue,char* dir);
int get_user_dir(char*pwd,dirID_t* dirID);
int changeDir(dirID_t*dirID ,int netfd);
int creatDirID(char * user,dirID_t*dirID);
int recDir(char *buf,dirQueue_t *dir);
int recvn(int sockfd, void *buf, int length);
int updatafile(int sockfd,dirID_t*dirID);
int userupdate(char* filename,int fileNameLen,int netfd,dirID_t*dirID);
int checkUser(userinfo_t*userinfo,int netfd);
int rm(int netfd,dirID_t* dirID);
int pwd(int netfd,dirID_t* dirID);
int myls(int netfd,dirID_t*dirID);//ls
int justify_Login_info(const char* username, const char* password);
int mkDir(dirID_t*dirID ,int netfd);
int rmDir(dirID_t*dirID ,int netfd);
int removeHiddenCharacters(const char *source, char *destination);
#endif
